<template>
    <div>
        <el-form class="form-box" ref="formRef" :model="form" label-width="auto" size="large">
            <el-row>
                <el-col :span="24">
                    <el-form-item label="收款金额：" prop="salaAmt">
                        <div class="salaAmt">{{ unpay }}</div>
                    </el-form-item>
                </el-col>

                <el-col :span="24">
                    <el-form-item label="低消金额：" prop="salaAmt">
                        <div class="salaAmt">{{ tableInfo.minConsume }}</div>
                    </el-form-item>
                </el-col>

                <el-col :span="24">
                    <el-form-item label="补低消：" prop="salaAmt">
                        <el-input v-model="form.salaAmt" placeholder="请输入金额" @focus="focusForm('salaAmt')" @blur="blurForm"
                            clearable oninput="value=value.replace(/[^0-9.]/g,'')"/>
                    </el-form-item>
                </el-col>

            </el-row>
        </el-form>
    </div>
</template>

<script setup >
import useConfigStore from '@/store/config'
const configStore = useConfigStore()
// 接收父组件参数 props
const props = defineProps({
    tableInfo: {
        type: Object,
        required: false,
    },
    selectWares: {
        type: Array,
        required: false,
    },
    saleData: {
        type: Array,
        required: false,
    },
    payData: {
        type: Array,
        required: false,
    },
    receive: {
        type: String,
        required: false,
    },
    form: {
        type: Object,
        required: false,
    },
    price: {
        type: String,
        required: false,
    },
    yhje: {
        type: String,
        required: false,
    },

    unpay: {
        type: String,
        required: false,
    },
})
const receive = toRef(props, 'receive')
const tableInfo = toRef(props, 'tableInfo')
const selectWares = toRef(props, 'selectWares')
const saleData = toRef(props, 'saleData')
const payData = toRef(props, 'payData')
const yhje = toRef(props, 'yhje')
const form = toRef(props, 'form')
const unpay = toRef(props, 'unpay')
const emit = defineEmits(['focusForm'])
// 数字键盘
const focusForm = (str) => {
    // keyboard.value = true
    emit('focusForm', str)
}
const blurForm = (params) => {
    // keyboard.value = false
}
// 切换form.saleType
const changeSaleType = () => {
    form.value.salaAmt = ''
    form.value.salaPercent = ''
    form.value.yhje = ''
}

// 父组件小键盘点击确定
const handleKeyboardConfirm = async(params) => {
    let flag = false
    saleData.value.forEach(item => {
        if (item.yhxm == form.value.actionType) {
            flag = true
        }
    });
    if (flag) return ElNotification({
        title: '提示',
        message: '已经存在补低消',
        type: 'warning',
    })
    console.log(tableInfo.value);
    console.log(unpay.value);
    
    if (Number(unpay.value) >= Number(tableInfo.value.minConsume)) return ElNotification({
        title: '提示',
        message: '无需补低消',
        type: 'warning',
    })
    const num = tableInfo.value.minConsume - unpay.value
    if (yhje.value > num) return ElNotification({
        title: '提示',
        message: '补低消不能大于 ' + -(-num),
        type: 'warning',
    })
    // if (Number(form.value.salaAmt) > Number(receive.value)  ) return ElNotification({
    //     title: '提示',
    //     message: '补低消金额不能大于应收金额',
    //     type: 'warning',
    // })
    const saleObj = {
        yhxm: form.value.actionType,
        je: yhje.value,
        code: tableInfo.value.payBatchCode,
        amt: yhje.value,
        type: form.value.actionType,
        subType: form.value.saleType,
    }
    saleData.value.push(saleObj)
    // console.log('saleData :>> ', saleData);
}

// 暴露方法给父组件
defineExpose({ handleKeyboardConfirm })



</script>

<style scoped lang="scss">
.form-box {
    margin-top: 20px;

    ::v-deep {
        .el-input__wrapper {
            background: #F9F9F9;
            border-radius: 8px;
            border: 0;
            font-size: 16px;
            color: #999999;
        }
    }

    .salaAmt {
        font-weight: 400;
        font-size: 16px;
        color: #FF3333;
    }

}
@import '@/styles/com_style_input.css';
</style>
